package cn.edu.njust.controller;

import cn.edu.njust.pojo.bo.LeaveBO;
import cn.edu.njust.pojo.bo.PageBean;
import cn.edu.njust.pojo.bo.RestResult;
import cn.edu.njust.pojo.dto.LeaveDTO;
import cn.edu.njust.pojo.dto.PageParamDTO;
import cn.edu.njust.pojo.po.User;
import cn.edu.njust.service.LeaveService;
import cn.edu.njust.service.UserService;
import cn.hutool.core.bean.BeanUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Tag(name = "学生管理接口")
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping("/student")
public class StudentController {

    private final LeaveService leaveService;

    private final UserService userService;

    /**
     * 学生请假业务
     *
     * @param leave 请假信息
     * @since 3.0.0
     */
    @Operation(summary = "请假")
    @GetMapping("/askForLeave")
    public RestResult<Void> askForLeave(@RequestBody LeaveDTO leave) {
        leaveService.addLeave(BeanUtil.copyProperties(leave, LeaveBO.class));
        return RestResult.success();
    }

    /**
     * 学生打卡业务
     */
    @Operation(summary = "打卡")
    @GetMapping("/punchIn")
    public RestResult<Void> punchIn() {
        userService.punchIn();
        return RestResult.success();
    }

    /**
     * 班长查看打卡异常名单
     *
     * @param pageParam 分页信息
     */
    @Operation(summary = "查看打卡异常名单")
    @PostMapping("/selectStudentInLeaves")
    public RestResult<PageBean<User>> selectStudentInLeaves(@RequestBody PageParamDTO pageParam) {
        return RestResult.success(userService.selectStudentInLeaves(pageParam.getPageNum(), pageParam.getPageSize()));
    }
}
